package com.example.libjava;

import com.example.libjava.ducks.MallardDuck;
import com.example.libjava.fly.FlyBehavior;
import com.example.libjava.fly.FlyNoWay;
import com.example.libjava.fly.FlyWithWings;
import com.example.libjava.quack.Quack;
import com.example.libjava.quack.QuackBehavior;

public abstract class Duck  {
    public void swim(){
        System.out.println("i can swim");
    };
    public abstract void display();

    FlyBehavior flyBehavior;
    QuackBehavior quackBehavior;

    public void setFlyBehavior(FlyBehavior fb) {
        this.flyBehavior = fb;
    }
    public void setQuackBehavior(QuackBehavior qb) {
        this.quackBehavior = qb;
    }

    public void performQuack() {
        if (quackBehavior!=null) {
            quackBehavior.quack();
        }
    }
    public void performFly() {
        if (flyBehavior!=null) {
            flyBehavior.fly();
        }
    }

    public static void main(String[] args) {
        Singleton config = Singleton.getSingleton();
        Duck mallard = new MallardDuck();
        mallard.display();
        if(config != null) {
            mallard.setFlyBehavior(new FlyWithWings());
        } else {
            mallard.setFlyBehavior(new FlyNoWay());
        }
        mallard.performFly();
        mallard.performQuack();
        //mallard.setFlyBehavior(new FlyNoWay());
        //mallard.performFly();
    }
}
